//
//  GraduateDisCtry.m
//  ZHZtest
//
//  Created by 李彦宏 on 2018/1/12.
//  Copyright © 2018年 LYH. All rights reserved.
//

#import "GraduateDisCtry.h"
#import "UndistributeCtry.h"//未分配
#import "AllocatedCtry.h"//已分配
#import "JWdistributSearchCtry.h"
#import "JWUserManager.h"
#import "SDUserModel.h"

@interface GraduateDisCtry ()
@property (nonatomic, strong) SDUserModel *SDmodel;
@property (nonatomic, strong) NSMutableArray *SDdislist;

@end

@implementation GraduateDisCtry

- (void)viewDidLoad {
    [super viewDidLoad];
     self.SDmodel=[JWUserManager SDme];
    [self setdataDistribut];
     NSLog(@"2222222");
    self.title=@"分配研究生情况";
    UIImage *image = [UIImage imageNamed:@"searchbar_textfield_search_icon"];
    // 取消图片渲染
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithImage: image style:UIBarButtonItemStyleDone target:self action:@selector(cancelDidClick)];
    [self setupAllChildViewController];
    // Do any additional setup after loading the view.
}
-(void)cancelDidClick{
    JWdistributSearchCtry *vc=[[JWdistributSearchCtry alloc]init];
    vc.tagsArray=[[NSMutableArray alloc]init];
    if(_SDdislist.count<7){
        vc.tagsArray=[NSMutableArray arrayWithObjects:@"李彦宏",@"朱圳",@"严戈闲",@"赵延",@"田涛",@"肖欢欣",@"游鹤亭",@"陈炽", nil];
        
    }else{
        
        for (int i=0; i<7; i++) {
            self.SDmodel=_SDdislist[i];
            [vc.tagsArray addObject:self.SDmodel.name];
        }
    }
    [self.navigationController pushViewController:vc animated:YES];
}
-(void)setupAllChildViewController
{
    //未分配
    UndistributeCtry *  Undistribute = [[UndistributeCtry alloc]init];
     Undistribute.title = @"未分配";
     Undistribute.view.backgroundColor = [UIColor whiteColor];
    [self addChildViewController: Undistribute];
    //已分配
    AllocatedCtry * Allocated = [[AllocatedCtry alloc]init];
    Allocated.title = @"已分配";
    Allocated.view.backgroundColor = [UIColor whiteColor];
    [self addChildViewController:Allocated];

}
#pragma -mark ————————————获取学生分配列表————————————————————
-(void)setdataDistribut{
    NSDictionary *dict=@{
                         @"jwid":JWid,
                         @"jwpassword":JWpassword,
                         };
    [[AFNetworkTool shareManager]postJSONWithUrl:JWteacher_SdistriList parmas:dict successData:^(id json) {
    //    NSLog(@"->>-json--%@", json);
        NSArray *arry=json[@"data"];
        __weak typeof(self) weakslf = self;
        for (int i=0; i<arry.count;i++) {
            self.SDmodel=[SDUserModel yy_modelWithJSON:arry[i]];
            //必须要用weakslf，避免重复引用
            [weakslf.SDdislist addObject:weakslf.SDmodel];
        }
    } failure:^(NSError *error) {
        NSLog(@"--error--%@", error);
    } ];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSMutableArray *)SDdislist{
    if(_SDdislist==nil){
        _SDdislist=[[NSMutableArray alloc]init];
    }
    return _SDdislist;
}

@end
